package com.zz.spring6.resources;

import org.springframework.core.io.UrlResource;

import java.net.MalformedURLException;

/**
 * 访问网络资源
 */
public class UrlResourcesDemo {

    public static void main(String[] args) {
        // http
        //loadUrlResources("http://www.baidu.com");
        // file
        loadUrlResources("file:zz.txt");
    }

    // 访问 http
    public static void loadUrlResources(String path){
        //1 创建实现类
        try {
            UrlResource url = new UrlResource(path);
            // 获取资源信息
            System.out.println(url.getFilename());
            System.out.println(url.getURL());
            System.out.println(url.getDescription());// 描述信息
            System.out.println(url.getInputStream().read());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
